#-*- coding:utf-8 -*-

from django.db import models
from django.contrib.auth.models import User

class Type(models.Model):
    STATUS_NORMAL = 1
    STATUS_DISABLED = 2
    STATUS_CHOICES = (
        (STATUS_NORMAL, "正常"),
        (STATUS_DISABLED, "禁用"),
    )
    
    name = models.CharField(max_length=100)
    status = models.PositiveIntegerField(choices=STATUS_CHOICES,default=STATUS_NORMAL)
    ts = models.DateTimeField(auto_now=True)

    def __unicode__(self):
        return self.name


class Trade(models.Model):
    STATUS_NORMAL = 0
    STATUS_DELETE = 1
    STATUS_CHOICES = ( (STATUS_NORMAL, "正常"), (STATUS_DELETE, "删除"),)

    ACT_RENT = 1
    ACT_SELL = 2
    ACT_REQRENT = 3
    ACT_BUY = 4
    ACT_CHOICES = ( (ACT_RENT, "出租"), (ACT_SELL, "出售"), (ACT_REQRENT, "求租"), (ACT_BUY, "求购"))

    STYLE_CHOICES = ( (1, "单间"), (2, "一房一厅"), (3, "两房一厅"), (4, "三房一厅"), (5, "三房两厅"), (6, "四房一厅"), (7, "四房两厅"), (8, "四房以上"))
    FITMENT_CHOICES = ((1, "毛坯"), (2, "普通装修"), (3, "精装修"), (4, "豪华装修"))
    SOUCE_CHOICES = ((1, "业主"), (2, "中介"))

    user = models.ForeignKey(User)
    ttype = models.ForeignKey(Type)
    actype = models.PositiveIntegerField(choices=ACT_CHOICES)
    area = models.PositiveIntegerField(default=0)
    style = models.PositiveIntegerField(default=0, choices=STYLE_CHOICES)
    fitment = models.PositiveIntegerField(default=0, choices=FITMENT_CHOICES)
    floor = models.PositiveIntegerField(default=0)
    addr = models.CharField(default='', max_length=128, blank=True)
    price = models.PositiveIntegerField(default=0)
    souce = models.PositiveIntegerField(default=0, choices=SOUCE_CHOICES)

    title = models.CharField(max_length=128, default='', blank=True)
    desc = models.TextField(max_length=2048, default='')
    phone = models.CharField(max_length=30) 
    reads = models.PositiveIntegerField(default=0)
    comments = models.PositiveIntegerField(default=0)
    status = models.SmallIntegerField(choices=STATUS_CHOICES, default=STATUS_NORMAL)
    posttime = models.DateTimeField(auto_now=True)


class Image(models.Model):
    owner = models.ForeignKey(User)
    trade = models.ForeignKey(Trade, null=True, blank=True)
    image = models.ImageField(upload_to="house")
    relative_path = models.CharField(max_length=128)
    size = models.PositiveIntegerField(default=0)
    posttime = models.DateTimeField(auto_now=True)

    def __unicode__(self):
        return self.relative_path

